Results Controller
-
A ResultsController manages data in a way that is usable by a collection view.
- FetchedResultsController
- RelationalResultsController
Declaration
Swift
public protocol ResultsController : AnyObject
-
The ResultsControllerDelegate defines methods that allow you to respond to changes in the results controller.
Use ResultChangeSet to easily track changes and apply them to a CollectionView
See moreDeclaration
Swift
public protocol ResultsControllerDelegate : AnyObject
-
The types of changes reported to ResultsControllerDelegate
- delete: The item was deleted
- update: The item was updated
- insert: The item was inserted
- move: The item was moved
Declaration
Swift
public enum ResultsControllerChangeType
-
Errors thrown by results controllers - unimplimented
- unknown:
Declaration
Swift
public enum ResultsControllerError : Error
-
A results controller not only manages data, it also provides an easy to use, consistent interface for working with CollectionViews. While a typical controller fetches and manages data changes internally, this slimmed down version leaves the manipulation of it’s content up to you so you can use the same interface with any type of data.
See moreDeclaration
Swift
public class MutableResultsController<Section, Element> : ResultsController where Section : SectionType, Element : ResultType
-
A FetchedResultsController provides the same data store and change reporting as a MutableResultsController but sources it’s contents from a CoreData context.
Given an NSFetchRequest, the results from the provided context are fetched and analyzed to provide the data necessary to populate a CollectionView.
The controller can also be sorted, grouped into sections and automatically updated when changes are made in the managed obejct context.
See moreDeclaration
Swift
public class FetchedResultsController<Section, Element> : MutableResultsController<Section, Element> where Section : SectionType, Element : NSManagedObject
-
Extending on FetchedResultsController and it’s section grouping, this controller allows for sections to be created from a parent ententy.-
In a FetchedResultsController (and NSFetchedResultsController) you would use sectionKeyPath to achieve the following:
Things { sectionKeyPath : "Things" } { sectionKeyPath : "Things" } Not Things { sectionKeyPath : "Not Things" } { sectionKeyPath : "Not Things" }
While this is great, it does not work well for the common Parent-Child data model. In a Department - Employee model for example we woul want:
Sales {} Jim {} Samantha {} Managment {} Sarah {} Howard {} Delivery {} <No employees>
In this case, both the parent and child are NSManagedObjects joined by a relationship. Also, notice the Delivery department has no employees. With a standard FetchedResultsController where sections consist of the available values in the fetched objects, the
See moreDelivery
would not be included. With a RelationalResultsController though you can opt to fetch both the sections and object independently (seefetchSections
).Declaration
Swift
public class RelationalResultsController<Section, Element> : FetchedResultsController<Section, Element> where Section : NSManagedObject, Element : NSManagedObject
-
A results controller that does not concern itself with the order of objects, but only their membership to the supplied fetch request.
See moreDeclaration
Swift
public class FetchedSetController : ContextObserver
-
A helper object to easily track changes reported by a ResultsController and apply them to a CollectionView
See moreDeclaration
Swift
public class CollectionViewProvider : CollectionViewResultsProxy
-
A Helper to convert data set changes into collection view edits
See moreDeclaration
Swift
public class CollectionViewResultsProxy : CustomDebugStringConvertible